package chapter17;

import java.util.PriorityQueue;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/11/28 12:33
 */
public class ToDoList extends PriorityQueue<ToDoList.ToDoItem> {

    public void add(String td, char pri, int sec) {
        super.add(new ToDoItem(pri, sec, td));
    }

    static class ToDoItem implements Comparable<ToDoItem> {
        private char primary;
        private int secondary;
        private String item;

        public ToDoItem(char primary, int secondary, String item) {
            this.primary = primary;
            this.secondary = secondary;
            this.item = item;
        }

        @Override
        public int compareTo(ToDoItem o) {
            if (this.primary > o.primary) {
                return 1;
            } else if (this.primary == o.primary) {
                if (this.secondary > o.secondary) {
                    return 1;
                } else if (this.secondary == o.secondary) {
                    return 0;
                }
            }
            return -1;
        }

        @Override
        public String toString() {
            return "ToDoItem{" +
                    "primary=" + primary +
                    ", secondary=" + secondary +
                    ", item='" + item + '\'' +
                    '}';
        }
    }
}
